WEBVTT

00:03.330 --> 00:05.040
Hello and welcome back to our costs.

00:05.070 --> 00:09.570
So in this session we learn about boolean indexing of some higher res.

00:09.600 --> 00:10.530
So what does it mean.

00:10.530 --> 00:17.040
So let's assume we have an umpire Ray with many elements and we want to check element y's if the element

00:17.040 --> 00:19.980
meets a certain conditions of like sample.

00:19.980 --> 00:24.480
You want to check if each element is greater than five or not.

00:24.480 --> 00:28.080
And with NUM PI we can do this in a vector rest fashion.

00:28.080 --> 00:33.210
So we do not need to write for loops or if elif and US statements.

00:33.360 --> 00:34.500
So let's start to code.

00:34.530 --> 00:35.430
Let's.

00:35.550 --> 00:36.420
Important umpire.

00:37.350 --> 00:42.750
And then we create an umpire Ray from 1 to 10 and then we check element twice.

00:42.750 --> 00:46.570
So we have a if a is greater than five.

00:46.570 --> 00:48.680
So we check for each element here.

00:48.730 --> 00:57.140
If the element is greater than five and what an umpire returns us it returns an umpire Ray with boolean

00:57.170 --> 00:58.320
objects.

00:58.330 --> 01:01.490
So here for the first elements of one is not greater than five.

01:01.490 --> 01:05.150
It gives us a false two is not greater than five false.

01:05.160 --> 01:14.090
And I can see here starting from six we get a true so an umpire returned us and boolean array on the

01:14.090 --> 01:21.520
Ravens US boolean objects and I called this a bully NRA mask ones that we see later what we can do with

01:21.520 --> 01:21.720
it.

01:23.920 --> 01:33.920
Then second we check if each element is less than eight and then we also get back in boolean array so

01:33.920 --> 01:39.870
we can see only the last three elements of our array does not fulfill the condition and gives us the

01:39.890 --> 01:46.780
false and we can also make it more complicated so we can have an and statement on and keywords here

01:47.070 --> 01:54.940
you can check which element fulfills both conditions so is greater than five and less than eight.

01:54.970 --> 02:01.520
So I would assume that the elements sixth and seventh so only two elements fulfill both conditions.

02:02.170 --> 02:04.330
So we are false false false and two times true.

02:04.330 --> 02:05.500
OK.

02:05.560 --> 02:09.640
And we can also take the R operator.

02:09.700 --> 02:12.310
So we check whether at least one condition is met.

02:12.310 --> 02:19.710
So at least the element is either greater than five or either less than eight.

02:20.410 --> 02:28.580
And this holds true for all elements so all elements at least fulfill one condition.

02:28.650 --> 02:35.820
So now what if we want the opposite of let's say our mask re so the opposite array where we have fear

02:35.880 --> 02:37.990
for each element and the opposite.

02:38.010 --> 02:46.920
Boolean value in the air we have to use the terrorism bill so this means uh not are the opposite of

02:46.920 --> 02:48.850
this expression here.

02:48.850 --> 02:49.860
So let's see what we get

02:53.190 --> 02:54.120
so let's check again.

02:54.130 --> 02:58.980
So we took you the opposite of mosque three so the opposite of forces.

02:58.980 --> 03:02.200
True False True False True.

03:02.370 --> 03:08.430
And yeah in the end so we saw here mosque three gets us to truth at Element Six and seven.

03:08.430 --> 03:13.650
And here we get truth and only two false at are the elements six and seven.

03:13.920 --> 03:15.920
And what we cannot do we cannot say.

03:16.050 --> 03:22.010
Instead of having the two the symbol become let's not say not so not does not work in an erect arised

03:22.020 --> 03:23.370
fashion.

03:23.370 --> 03:25.420
And it gives us here the value area.

03:25.530 --> 03:29.440
So the truth value of an array with more than one element is ambiguous.

03:29.520 --> 03:38.050
So not does not work in this case so we have to take here the two the symbol All right so so far we

03:38.050 --> 03:44.140
created a new and the Array method the Boolean value is that shows us whether the elements fulfilled

03:44.170 --> 03:45.760
the condition or not.

03:45.760 --> 03:51.170
And yeah what if we want to filter out the elements which fulfill that condition.

03:51.250 --> 03:54.390
So let's say here a great fire.

03:54.400 --> 03:59.470
So we want to filter out all the elements which are greater than five or six seven eight nine ten.

03:59.860 --> 04:02.000
And we can do this by brilliant indexing.

04:02.020 --> 04:04.890
So we take a and then it's paprika.

04:04.910 --> 04:09.920
We take the condition a create a five and a grade of five as a boolean in the array.

04:10.120 --> 04:12.450
Let's see what happens.

04:12.460 --> 04:21.010
So now num high returns us an array on a slice of array a we had the condition a greater than five is

04:21.010 --> 04:21.680
fulfilled.

04:21.940 --> 04:28.870
So when instead of writing here and spell brackets our condition we can just put in our mask one for

04:28.870 --> 04:31.990
example the condition of mask one is a greater five.

04:32.050 --> 04:34.310
So we already did this here.

04:34.390 --> 04:37.250
So we should get the same result.

04:37.300 --> 04:40.270
So now we want to slice a four hour mask too.

04:40.300 --> 04:43.340
So mask to what this mask to doing.

04:43.570 --> 04:46.620
The condition of mask to us all elements.

04:46.630 --> 04:50.160
Less than eight let's see.

04:52.110 --> 04:58.410
So we get all the elements until seven and mask three it should give us a six and seven.

04:58.530 --> 04:59.520
We already had that.

04:59.550 --> 05:05.410
Yes mask for should give us all elements

05:08.610 --> 05:15.450
so all elements either fulfil the condition one or condition two and mask five through should return

05:15.450 --> 05:20.700
us them the opposite of mask three or so all elements but not Element Six and Seven

05:23.750 --> 05:26.400
back and sit here so six and seven are missing.

05:27.180 --> 05:27.540
All right.

05:27.540 --> 05:33.300
So this is set for boolean indexing and in the next session we will learn about how to create random

05:33.300 --> 05:35.040
numbers with NUM pi.

05:35.040 --> 05:35.640
See you there.
